'''
Author: Simon
Date: 2022-03-10 16:37:56
LastEditTime: 2022-03-10 16:57:39
LastEditors: Please set LastEditors
Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
FilePath: \pytorch-tutorial\Tensorboard\\add_image.py
'''
# SummaryWriter 类的使用
# Running: tensorboard --logdir=logs --port=6007

from torch.utils.tensorboard import SummaryWriter
from PIL import Image
import numpy as np


# 存储到 logs/ 文件夹下
writer = SummaryWriter("logs")


# PIL 读入 image：类型为 PIL Image 类型，需要转换为 Tensor or Numpy
image_path = "dataset\hymenoptera_data\hymenoptera_data\\train\\ants\\0013035.jpg"
img_PIL = Image.open(image_path)
img_array = np.array(img_PIL)
print(type(img_array))
print(img_array.shape)


# add_image(tag, img_tensor, global_step)
# img_tensor: torch.Tensor, numpy
    # Default Shape: (3, H, W)
    # if different shape: (H, W, 3), need to set dataformats: CHW, HWC, HW
# global_step: 训练次数
writer.add_image("image", img_array, 1, dataformats="HWC")


writer.close()